/*
 * * * Compile_AHK SETTINGS BEGIN * * *

[AHK2EXE]
Exe_File=C:\Dropbox\SVN\PM App Launcher\Include\Threads\Threads.exe
Created_Date=1
Execution_Level=2
[VERSION]
Resource_Files=C:\Dropbox\SVN\PM App Launcher\Resource\THD_icon.ico
Set_Version_Info=1
Company_Name=WSNH Apps
File_Description=Quickly look up blanking dims and/or connection data for different threads
File_Version=1.0.0.6
Inc_File_Version=1
Internal_Name=Threads.exe
Legal_Copyright=WSNH Apps
Original_Filename=Threads.exe
Product_Name=AutoHotkey_L
Product_Version=1.1.5.3
Set_AHK_Version=1
[ICONS]
Icon_1=C:\Dropbox\SVN\PM App Launcher\Resource\THD_icon.ico

* * * Compile_AHK SETTINGS END * * *
*/

;*********************************************************************
; File: Threads
;_____________________________________________________________________
;---------------------------------------------------------------------
; 	Application that allows user to select a thread type from a drop
; 	down list and directly open to the page containing either its
; 	blanking or connection data sheet. If site is not pre-loaded,
; 	the thread type and "connection data" or "Blanking dimensions"
; 	will be searched in Google.
;
;	(see THD_ScreenShot.png)
;
; Group: About
;	General script information
;
;	- *Original by:*	Sam Tehven
;	- *Modified by:*	Rameen Bakhtiary
; 	- *Last modified:*	10/27/2011
;---------------------------------------------------------------------
 #NoEnv
 #SingleInstance, Ignore
 SetWorkingDir %A_ScriptDir%
 SetTitleMatchMode, 2
 SendMode, Input 
 Functions()
;_____________________________________________________________________
;---------------------------------------------------------------------




;___________________________________________________
;					Tray icon from compile Resources
;
if A_IsCompiled
	menu, tray, icon, % A_ScriptFullPath, -159



;___________________________________________________
;								Global  Variables
;
INI_FILE 	= \\corp.halliburton.com\team\WD\Business Development And Technology\General\Engineering Public\PM App Launcher\Threads\blanking_Connection.ini
HELP_FILE	= %A_MyDocuments%\PM App Launcher\Resource\THD_help.txt



;___________________________________________
;						Load info from INI
;
Loop{
	iniread,thisOne, %INI_File%, threads, %a_index%
	If (thisOne = "ERROR"){
		Tnum := a_index-1
		break
	}
	if !threads
		threads:=thisOne
	else
		Threads .= "|" . thisOne
}
goto main



;_______________________________
;					Build GUI
;
Main:
	Gui, -caption
	Gui, +border
	;~ Gui, +toolmenu
	Gui, Add, ComboBox, x16 y37 w160 h10 r%Tnum% vbdata Uppercase, %Threads%
	Gui, Add, Text, x24 y40 w150 h15 +BackgroundTrans cblue, Choose or Type Thread >>
	gui, font, w700
	Gui, Add, GroupBox, x6 y17 w270 h50, BLANKING DIMENSIONS
	Gui, Add, Button, x186 y37 w80 h20 gblankit, BLANK-IT
	gui, font, w400
	Gui, Add, ComboBox, x16 y97 w160 h20 r%Tnum% vcdata Uppercase, %Threads%
	Gui, Add, Text, x24 y100 w150 h20 +BackgroundTrans cblue, Choose or Type Thread >>
	gui, font, w700
	Gui, Add, GroupBox, x6 y77 w270 h50, CONNECTION DATA
	Gui, Add, Button, x186 y97 w80 h20 gconnect, CONNECT
	Gui, Add, Button, x235 y2 w20 h20 ghelp, ?
	Gui, Add, Button, x255 y2 w20 h20 gGuiclose, X
	Gui, Show, w281 h129, THREAD DATA VERSION %Version%
Return





;_____________________________________________
;							Show help file
;
help:
	FileRead, helpfile, %HELP_FILE%
	MsgBox, 4160, Thread Help, %helpfile%
return






;_________________________________________________
;					BUTTON:  Get blanking dims
;
blankit:
	Gui, Submit, nohide
	If !(bdata){		;Submitted blank GUI
		MsgBox, 4112, OOOPS!, You must choose a thread type before clicking BLANK-IT.
		ControlFocus, Edit1, THREAD DATA
		return
	}
	Gui, Destroy
	If InStr(threads, bdata){	;Found in INI... run it
		Run, % IniRead(INI_File, "blanking", bdata)
		ExitApp
	}
	;Not in INI - Search Google
	Run, http://www.google.com/search?hl=en&source=hp&q=%search% Blanking Dimensions
ExitApp





;________________________________________________
;				BUTTON:  Get connection data
;
connect:
	Gui, Submit, nohide
	If (cdata = ""){		;Submitted blank GUI
		MsgBox, 4112, OOOPS!, You must choose a thread type before clicking CONNECT.
		ControlFocus, Edit2, THREAD DATA
		return
	}
	gui, destroy
	If InStr(threads, cdata){	;Found in INI...Run it
		Run, % iniread(INI_File, "connection", cdata)
		ExitApp
	}	
	;Not in INI - Search Google
	Run, http://www.google.com/search?hl=en&source=hp&q=%search% Connection Data
ExitApp





;_________________________________________________
;					Hotkey: <Enter> to submit
;
#ifwinactive, THREAD DATA
enter::
	ControlGetFocus, buttonfokus, THREAD DATA
	Goto, % buttonFokus = "Edit1" ? "blankit" : "connect"
return





;______________________________________
;						Close / Exit
;
GuiEscape:
GuiClose:
	ExitApp
return